package leetcode.offer_two_special.string;

/**
 * @author mazouri
 * @create 2021-09-06 19:44
 */
public class _18_isPalindrome {
    public boolean isPalindrome(String s) {
        int i = 0;
        int j = s.length() - 1;

        while (i < j) {
            char leftChar = s.charAt(i);
            char rightChar = s.charAt(j);
            if (!Character.isLetterOrDigit(leftChar)) i++;
            else if (!Character.isLetterOrDigit(rightChar)) j--;
            else {
                leftChar = Character.toLowerCase(leftChar);
                rightChar = Character.toLowerCase(rightChar);

                if (leftChar != rightChar) return false;

                i++;
                j--;
            }
        }
        return true;
    }
}
